package com.ssy.lingxi.settle.accounts.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.dto.model.constant.SettlementHelpEnum;

import java.util.Arrays;

/**
 * 对账单类型枚举
 * @author Saske
 * @date 2021/12/10
 * @version 2.0.0
 */
public enum  ReconciliationTypeEnum {

    /**
     * 物料对账单
     */
    MATERIAL(1, "物料对账单"),

    /**
     * 订单
     */
    ORDER(2, "订单"),

    /**
     * 退货申请单
     */
    RETURN_APPLY(3, "退货申请单"),

    /**
     * 积分订单
     */
    INTEGRAL(4, "积分订单"),

    /**
     * 物流单
     */
    LOGISTICS(5, "物流单"),

    /**
     * 生产通知单
     */
    PRODUCE_NOTICE(6, "生产通知单");

    private final Integer code;
    private final String message;

    ReconciliationTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    /**
     * 根据状态枚举值获得状态名称
     * @param code 外部状态枚举值
     * @return 外部状态名称
     */
    public static String getNameByCode(Integer code) {
        ReconciliationTypeEnum statusEnum = Arrays.stream(ReconciliationTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return statusEnum == null ? SettlementHelpEnum.UNKNOWN.getMessage() : statusEnum.getMessage();
    }
}
